home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / formats / _image.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  6KB  |  213 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4.  
  5. class ImageContainer(object):
  6.     '''Mixin/Interface for AudioFile to support basic embedded image editing'''
  7.     
  8.     def get_primary_image(self):
  9.         '''Returns the primary embedded image or None.'''
  10.         pass
  11.  
  12.     
  13.     def get_images(self):
  14.         '''Returns a list of embedded images, primary first'''
  15.         image = self.get_primary_image()
  16.         if image:
  17.             return [
  18.                 image]
  19.  
  20.     
  21.     def has_images(self):
  22.         '''Fast way to check for images, might be False if the file
  23.         was modified externally.
  24.         '''
  25.         return '~picture' in self
  26.  
  27.     has_images = property(has_images)
  28.     
  29.     def has_images(self, value):
  30.         if value:
  31.             self['~picture'] = 'y'
  32.         else:
  33.             self.pop('~picture', None)
  34.  
  35.     has_images = has_images.setter(has_images)
  36.     
  37.     def can_change_images(self):
  38.         '''Return True IFF `clear_images()` and `set_images()` are
  39.         implemented'''
  40.         return False
  41.  
  42.     can_change_images = property(can_change_images)
  43.     
  44.     def clear_images(self):
  45.         '''Delete all embedded images'''
  46.         raise NotImplementedError
  47.  
  48.     
  49.     def set_image(self, image):
  50.         '''Replaces all embedded images by the passed image.
  51.  
  52.         The image type recorded in the file will be APICType.COVER_FRONT,
  53.         disregarding image.type.
  54.         '''
  55.         raise NotImplementedError
  56.  
  57.  
  58.  
  59. class APICType(object):
  60.     '''Enumeration of image types defined by the ID3 standard but also reused
  61.     in WMA/FLAC/VorbisComment
  62.     '''
  63.     OTHER = 0
  64.     FILE_ICON = 1
  65.     OTHER_FILE_ICON = 2
  66.     COVER_FRONT = 3
  67.     COVER_BACK = 4
  68.     LEAFLET_PAGE = 5
  69.     MEDIA = 6
  70.     LEAD_ARTIST = 7
  71.     ARTIST = 8
  72.     CONDUCTOR = 9
  73.     BAND = 10
  74.     COMPOSER = 11
  75.     LYRISCIST = 12
  76.     RECORDING_LOCATION = 13
  77.     DURING_RECORDING = 14
  78.     DURING_PERFORMANCE = 15
  79.     SCREEN_CAPTURE = 16
  80.     FISH = 17
  81.     ILLUSTRATION = 18
  82.     BAND_LOGOTYPE = 19
  83.     PUBLISHER_LOGOTYPE = 20
  84.     
  85.     def to_string(cls, value):
  86.         for k, v in cls.__dict__.items():
  87.             if v == value:
  88.                 return k
  89.         
  90.         return ''
  91.  
  92.     to_string = classmethod(to_string)
  93.     
  94.     def is_valid(cls, value):
  95.         if value <= value:
  96.             return value <= cls.PUBLISHER_LOGOTYPE
  97.         value <= value
  98.         return value
  99.  
  100.     is_valid = classmethod(is_valid)
  101.     
  102.     def sort_key(cls, value):
  103.         '''Sorts picture types, most important picture is the lowest.
  104.         Important is defined as most representative of an album release, ymmv.
  105.         '''
  106.         important = [
  107.             cls.LEAFLET_PAGE,
  108.             cls.MEDIA,
  109.             cls.COVER_BACK,
  110.             cls.COVER_FRONT]
  111.         
  112.         try:
  113.             return -important.index(value)
  114.         except ValueError:
  115.             if value < cls.COVER_FRONT:
  116.                 return 100 - value
  117.             return None
  118.  
  119.  
  120.     sort_key = classmethod(sort_key)
  121.  
  122.  
  123. class EmbeddedImage(object):
  124.     '''Embedded image, contains most of the properties needed
  125.     for FLAC and ID3 images.
  126.     '''
  127.     
  128.     def __init__(self, fileobj, mime_type, width = -1, height = -1, color_depth = -1, type_ = APICType.OTHER):
  129.         self.mime_type = mime_type
  130.         self.width = width
  131.         self.height = height
  132.         self.color_depth = color_depth
  133.         self.file = fileobj
  134.         self.type = type_
  135.  
  136.     
  137.     def __repr__(self):
  138.         return '<%s mime_type=%r width=%d height=%d type=%s file=%r>' % (type(self).__name__, self.mime_type, self.width, self.height, APICType.to_string(self.type), self.file)
  139.  
  140.     
  141.     def sort_key(self):
  142.         return APICType.sort_key(self.type)
  143.  
  144.     sort_key = property(sort_key)
  145.     
  146.     def extensions(self):
  147.         '''A possibly empty list of extensions e.g. ["jpeg", jpg"]'''
  148.         GdkPixbuf = GdkPixbuf
  149.         import gi.repository
  150.         for format_ in GdkPixbuf.Pixbuf.get_formats():
  151.             if self.mime_type in format_.get_mime_types():
  152.                 return format_.get_extensions()
  153.         
  154.         return []
  155.  
  156.     extensions = property(extensions)
  157.     
  158.     def from_path(cls, path):
  159.         '''Reads the header of `path` and creates a new image instance
  160.         or None.
  161.         '''
  162.         GdkPixbuf = GdkPixbuf
  163.         GLib = GLib
  164.         import gi.repository
  165.         pb = []
  166.         
  167.         def area_prepared(loader):
  168.             pb.append(loader.get_pixbuf())
  169.  
  170.         loader = GdkPixbuf.PixbufLoader()
  171.         loader.connect('area-prepared', area_prepared)
  172.         
  173.         try:
  174.             with open(path, 'rb') as h:
  175.                 while not pb:
  176.                     data = h.read(1024)
  177.                     if data:
  178.                         loader.write(data)
  179.                         continue
  180.                     break
  181.         except (EnvironmentError, GLib.GError):
  182.             (None,)
  183.             (None,)
  184.             return None
  185.         finally:
  186.             
  187.             try:
  188.                 loader.close()
  189.             except GLib.GError:
  190.                 (None,)
  191.  
  192.  
  193.         if not pb:
  194.             return None
  195.         pb = (None,)[0]
  196.         width = pb.get_width()
  197.         height = pb.get_height()
  198.         color_depth = pb.get_bits_per_sample()
  199.         format_ = loader.get_format()
  200.         mime_types = format_.get_mime_types()
  201.         if not mime_types or mime_types[0]:
  202.             pass
  203.         mime_type = ''
  204.         
  205.         try:
  206.             return cls(open(path, 'rb'), mime_type, width, height, color_depth)
  207.         except EnvironmentError:
  208.             return None
  209.  
  210.  
  211.     from_path = classmethod(from_path)
  212.  
  213.